package com.zy.Conterller;

import com.zy.pojo.Supper;
import com.zy.service.LinkmanService;
import com.zy.vo.ResultVo;
import com.zy.vo.Supper.SupperVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/linkman")
public class LinkmanController {

    @Resource
    public LinkmanService linkmanService;


    @GetMapping("/pagelist/{pageSize}/{pageNo}")
    public ResultVo getLinkmanList(@PathVariable Integer pageSize, @PathVariable Integer pageNo, SupperVo supperVo){
        return ResultVo.success(linkmanService.getPage(pageNo,pageSize,supperVo));
    }



    @PostMapping("/linkmanadd")
    public ResultVo add(@RequestBody Supper supper, HttpSession session){

        try{
            linkmanService.getlinkmanadd(supper);
            return ResultVo.success("角色添加成功!");
        }catch (Exception e){
            return ResultVo.fail("角色添加失败!",e);
        }
    }

    @PostMapping("/linkmanupdate")
    public  ResultVo update(@RequestBody Supper supper, HttpSession session){
        try {
            linkmanService.getlinkmanupdate(supper);
            return ResultVo.success("角色修改成功!");
        }catch (Exception e){
            return  ResultVo.fail("角色修改失败!",e);
        }
    }

    @GetMapping("linkmandel/{id}")
    public ResultVo del(@PathVariable String id){
        try {
            linkmanService.getlinkmandel(Integer.parseInt(id));
            return ResultVo.success("删除成功!");
        }catch (Exception e){
            return ResultVo.fail("删除失败！！",e);
        }
    }
}
